log using "\\file\UsersW$\wrr15\Home\My Documents\My Files\META-ANALYSIS AND PUBLICATION BIAS\REVISION FOR RESEARCH SYNTHESIS METHODS\PROGRAMS\TABLE2middle.smcl", replace
// This program takes about 2 hours to run on a standard laptop
etime, start
drop _all
clear
graph drop _all
set more off
set seed 52256
matrix RESULTS = J(4,6,0)
set matsize 10000
local studies = 1000
// Select is used to set the probability of being included in the data set
// when the study is subject to publication bias, either because (i) abs(tstat) < 2, or
// coef < 0. 
local select = 0.10
local obs = 100
local alpha = 1

                simulate effectMED = r(effectMED) effectMIN = r(effectMIN) effectP5 = r(effectP5) ///
						 effectP95 = r(effectP95) effectMAX = r(effectMAX)  ///
						 teffectMED = r(teffectMED) teffectMIN = r(teffectMIN) teffectP5 = r(teffectP5) ///
						 teffectP95 = r(teffectP95) teffectMAX = r(teffectMAX)  ///	
						 N = r(N) I2 = r(I2) pctsig = r(pctsig) , ///
                         reps(1000): sample, alpha(`alpha') studies(`studies') select(`select') obs(`obs') 						 
						 
                summ effectMED, meanonly
                matrix RESULTS[1,1] = r(mean)
                summ effectMIN, meanonly
                matrix RESULTS[1,2] = r(mean)
                summ effectP5, meanonly
                matrix RESULTS[1,3] = r(mean)
                summ effectP95, meanonly
                matrix RESULTS[1,4] = r(mean)
                summ effectMAX, meanonly
                matrix RESULTS[1,5] = r(mean)
                summ N, meanonly
                matrix RESULTS[1,6] = r(mean)
				
				summ teffectMED, meanonly
                matrix RESULTS[2,1] = r(mean)
                summ teffectMIN, meanonly
                matrix RESULTS[2,2] = r(mean)
                summ teffectP5, meanonly
                matrix RESULTS[2,3] = r(mean)
                summ teffectP95, meanonly
                matrix RESULTS[2,4] = r(mean)
                summ teffectMAX, meanonly
                matrix RESULTS[2,5] = r(mean)
                summ N, meanonly
                matrix RESULTS[2,6] = r(mean)
								
				summ pctsig, detail
				matrix RESULTS[3,1] = r(mean)
				matrix RESULTS[3,2] = r(min)		
				matrix RESULTS[3,3] = r(p5)
				matrix RESULTS[3,4] = r(p95)
				matrix RESULTS[3,5] = r(max)
                summ N, meanonly
                matrix RESULTS[3,6] = r(mean)	
				
				summ I2, detail
				matrix RESULTS[4,1] = r(mean)
				matrix RESULTS[4,2] = r(min)		
				matrix RESULTS[4,3] = r(p5)
				matrix RESULTS[4,4] = r(p95)
				matrix RESULTS[4,5] = r(max)
                summ N, meanonly
                matrix RESULTS[4,6] = r(mean)	
				

matrix colnames RESULTS = MED MIN P5 P95 MAX N
matrix rownames RESULTS = EFFECT TEFFECT PCTSIG HETERO 
matrix list RESULTS

etime

log close
